/**
 * 
 */
package com.ms.service.module.baccarat;

import java.math.BigDecimal;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import com.ms.service.module.baccarat.bin.BacrBetType;
import com.xpec.c4.game.common.Helper;
import com.xpec.c4.game.utility.GUID;
import com.xpec.c4.game.utility.GameUtility;

/**
 * 玩家各押注部位得分資訊
 * 
 * @author TW15010
 */
public class BacrPlayerGetScoreInfo {
	/** log4j object */
	private static final Log log = LogFactory.getLog(BacrPlayerGetScoreInfo.class);

	/**
	 * player id
	 */
	private GUID playerId;

	/**
	 * 押閒得分
	 */
	private BigDecimal player;

	/**
	 * 押莊得分
	 */
	private BigDecimal banker;

	/**
	 * 押和得分
	 */
	private BigDecimal tie;

	/**
	 * 押閒對得分
	 */
	private BigDecimal playerPair;

	/**
	 * 押莊對得分
	 */
	private BigDecimal bankerPair;

	public BigDecimal getPlayer() {
		return player;
	}

	public void setPlayer(BigDecimal player) {
		this.player = player;
	}

	public BigDecimal getBanker() {
		return banker;
	}

	public void setBanker(BigDecimal banker) {
		this.banker = banker;
	}

	public BigDecimal getTie() {
		return tie;
	}

	public void setTie(BigDecimal tie) {
		this.tie = tie;
	}

	public BigDecimal getPlayerPair() {
		return playerPair;
	}

	public void setPlayerPair(BigDecimal playerPair) {
		this.playerPair = playerPair;
	}

	public BigDecimal getBankerPair() {
		return bankerPair;
	}

	public void setBankerPair(BigDecimal bankerPair) {
		this.bankerPair = bankerPair;
	}

	/**
	 * 取得加總的分數
	 * 
	 * @return
	 */
	public BigDecimal getTotalScore() {
		BigDecimal total = BigDecimal.ZERO;

		if (player != null) {
			total = Helper.add(total, player);
		}

		if (banker != null) {
			total = Helper.add(total, banker);
		}

		if (tie != null) {
			total = Helper.add(total, tie);
		}

		if (playerPair != null) {
			total = Helper.add(total, playerPair);
		}

		if (bankerPair != null) {
			total = Helper.add(total, bankerPair);
		}

		return total;
	}

	public GUID getPlayerId() {
		return playerId;
	}

	public void setPlayerId(GUID playerId) {
		this.playerId = playerId;
	}

	/**
	 * 用押注類型來設定得分
	 * 
	 * @param betType
	 *            {@link BacrBetType}
	 * @param score
	 */
	public void setScoreByBetType(int betType, BigDecimal score) {
		switch (betType) {
		case BacrBetType.PLAYER:
			player = score;
			break;
		case BacrBetType.BANKER:
			banker = score;
			break;
		case BacrBetType.TIE:
			tie = score;
			break;
		case BacrBetType.PLAYER_PAIR:
			playerPair = score;
			break;
		case BacrBetType.BANKER_PAIR:
			bankerPair = score;
			break;
		default:
			if (log.isErrorEnabled()) {
				GameUtility.logErrorException(log, "invalid bet type " + betType);
			}
			break;
		}
	}
}
